from django.db import models

from apps.api_tests.models import InterFace
from utils.models import table_prefix


# Create your models here.


class BugManage(models.Model):
    """bug管理的模型类"""
    interface = models.ForeignKey(
        to=InterFace, on_delete=models.CASCADE,
        verbose_name="所属接口", help_text="所属接口", db_comment="所属接口"
    )
    create_time = models.DateTimeField(
        auto_now_add=True,
        help_text="提交时间", verbose_name="提交时间", db_comment="提交时间"
    )
    desc = models.CharField(
        max_length=30,
        blank=True,
        verbose_name="bug描述", help_text="bug描述", db_comment="bug描述"
    )
    # bug状态：处理中、未处理、已关闭、无效bug
    status = models.CharField(
        max_length=10,
        help_text="bug状态", verbose_name="bug状态", db_comment="bug状态"
    )
    user = models.CharField(
        max_length=10,
        blank=True,
        help_text="提交者", verbose_name="提交者", db_comment="提交者"
    )
    info = models.JSONField(
        default=dict,
        blank=True,
        help_text="用例执行信息", verbose_name='用例执行信息', db_comment="用例执行信息"
    )

    def __str__(self):
        return str(self.id)

    class Meta:
        db_table = table_prefix + 'bugManage'
        db_table_comment = 'bug管理表'

        verbose_name = 'bug管理表'
        verbose_name_plural = verbose_name


class BugHandle(models.Model):
    """bug处理记录表"""
    create_time = models.DateTimeField(
        auto_now_add=True,
        verbose_name='创建时间', help_text='创建时间', db_comment='创建时间'
    )
    bug = models.ForeignKey(
        to='BugManage', on_delete=models.CASCADE,
        help_text='bug ID', verbose_name='bug ID', db_comment='bug ID'
    )
    handle = models.TextField(
        blank=True,
        help_text='处理操作', verbose_name='处理操作', db_comment='处理操作'
    )
    update_user = models.CharField(
        max_length=32,
        blank=True,
        verbose_name='更新用户', help_text='更新用户', db_comment='更新用户'
    )

    class Meta:
        db_table = table_prefix + 'bug_handle'
        db_table_comment = 'bug处理记录表'

        verbose_name = "bug操作记录表"
        verbose_name_plural = verbose_name
